#include "Options.h"

#include <boost/algorithm/string.hpp>
#include <exception>
#include <iostream>
#include <fstream>
#include "Tools.h"


using namespace std;

Options::Options(void)
{
	ifstream myStream;
	myStream.open("config.ini",ios_base::in);
	string aLine;

	if(myStream.is_open())
	{
		while( !myStream.eof())
		{
			getline(myStream,aLine);
			Parse(aLine);
		}

		myStream.close();
	}

	if(myOptions.size() != 7)
		throw exception(/*"wrong config file"*/);

}

void Options::Parse(std::string &line)
{
	if(line.empty())
		return;

	boost::algorithm::trim(line);

	if(line[0] == '#')
		return;

	pair<string,string> aResult = Tools::Separate(line,':',true);

	if(aResult.first.empty() || aResult.second.empty())
		return;

	boost::algorithm::trim(aResult.first);
	boost::algorithm::trim(aResult.second);

	myOptions.push_back(aResult);
}


string Options::GetData(std::string theName)
{
	for(size_t i =0; i < myOptions.size(); i++)
	{
		if(theName == myOptions[i].first)
			return myOptions[i].second;
	}

	string notFound;
	return notFound;
}
